<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CIBlog
 *
 * 使用codeigniter框架开发的一个博客。
 * 
 * @package     ciblog
 * @author      Eric
 * @copyright   Copyright (c) 2011 - 2012, Eric
 * @license     GNU General Public License 2.0
 * @link        http://www.hebaijun.com
 * @version     1.0
 */

 //----------------------------------------------------------

 /**
  * 主页控制器
  *
  * 控制主页的一些显示信息
  *
  * @package     ciblog
  * @subpackage  Controllers
  * @category    Admin Controllers
  * @author      Eric <baijun.he@163.com>
  * @link        http://www.hebaijun.com
  */
class Admin extends HT_Controller {

	/**
	 * 默认方法
	 *
	 * @access   public
	 * @return   void
	 */
	public function index()
	{
		$data['bloginfo'] = $this->option_m->load_all_options();
		$data['current_title'] = $this->lang->line('admin_home').' - '.$this->lang->line('admin_title').' - '.$data['bloginfo']['blogname'];

		$data['current_location'] = 'admin_home';
		
		//用户信息
		$users = $this->ion_auth->user()->result();
		$data['users'] = $users[0];

		//概况
		$post_num = $this->post_m->load_posts('COUNT(*) as total_rows');
		$data['post_num'] = $post_num[0]->total_rows;
		$page_num = $this->page_m->load_pages('COUNT(*) as total_rows');
		$data['page_num'] = $page_num[0]->total_rows;
		$cat_num = $this->category_m->get_category('COUNT(*) as total_rows');
		$data['cat_num'] = $cat_num[0]->total_rows;
		$tag_num = $this->tag_m->get_tag('COUNT(*) as total_rows');
		$data['tag_num'] = $tag_num[0]->total_rows;
		$this->load->model('comment_m');
		$comment_num = $this->comment_m->load_comments('COUNT(*) as total_rows');
		$data['comment_num'] = $comment_num[0]->total_rows;
		$comment_allow_num = $this->comment_m->load_comments('COUNT(*) as total_rows', array('comment_approved' => '1'));
		$data['comment_allow_num'] = $comment_allow_num[0]->total_rows;
		$comment_pending_num = $this->comment_m->load_comments('COUNT(*) as total_rows', array('comment_approved' => '0'));
		$data['comment_pending_num'] = $comment_pending_num[0]->total_rows;
		$comment_spam_num = $this->comment_m->load_comments('COUNT(*) as total_rows', array('comment_approved' => 'spam'));
		$data['comment_spam_num'] = $comment_spam_num[0]->total_rows;

		//取最新5个评论
		$comment_search_array = array(
			'limit' => 5,
			'orderby' => 'comment_date',
			'order' => 'DESC'
		);
		$comments = $this->comment_m->load_comments('*',$comment_search_array);
		foreach($comments as $key=>$val)
		{
			$post_title = $this->comment_m->get_post_comment('post_title', array('post_id'=>$val->comment_post_id));
			$comments[$key]->post_title = $post_title[0]->post_title;
		}
		$data['comment_new'] = $comments;


		//var_dump($data);exit;

		$this->load->view('admin/admin', $data);
	}

}

/* End of file admin.php */
/* Location: ./application/controllers/admin/admin.php */